<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>Git速查手册 | Jimmey-Jiang&#39;s Blog</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="安装Linux打开控制台，然后通过包管理安装，在Ubuntu上命令是：1sudo apt-get install git-all Windows推荐使用git forwindows，它包括了图形工具以及命令行模拟器。 OS X最简单的方式是使用homebrew安装，命令行执行1brew install git 如果你是在是先用图形工具的话，那么推荐你使用Github desktop,Sourcet">
<meta name="keywords" content="Git">
<meta property="og:type" content="article">
<meta property="og:title" content="Git速查手册">
<meta property="og:url" content="http://Jimmey-Jiang.github.io/2017/08/19/Tool/Git/index.html">
<meta property="og:site_name" content="Jimmey-Jiang&#39;s Blog">
<meta property="og:description" content="安装Linux打开控制台，然后通过包管理安装，在Ubuntu上命令是：1sudo apt-get install git-all Windows推荐使用git forwindows，它包括了图形工具以及命令行模拟器。 OS X最简单的方式是使用homebrew安装，命令行执行1brew install git 如果你是在是先用图形工具的话，那么推荐你使用Github desktop,Sourcet">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http://img.blog.csdn.net/20161219162011600?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxNDM0NjMwMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">
<meta property="og:updated_time" content="2017-08-16T05:15:59.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Git速查手册">
<meta name="twitter:description" content="安装Linux打开控制台，然后通过包管理安装，在Ubuntu上命令是：1sudo apt-get install git-all Windows推荐使用git forwindows，它包括了图形工具以及命令行模拟器。 OS X最简单的方式是使用homebrew安装，命令行执行1brew install git 如果你是在是先用图形工具的话，那么推荐你使用Github desktop,Sourcet">
<meta name="twitter:image" content="http://img.blog.csdn.net/20161219162011600?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxNDM0NjMwMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">
  
    <link rel="alternative" href="/atom.xml" title="Jimmey-Jiang&#39;s Blog" type="application/atom+xml">
  
  
    <link rel="icon" href="/img/favicon.png">
  
  
      <link rel="stylesheet" href="//cdn.bootcss.com/animate.css/3.5.0/animate.min.css">
  
  <link rel="stylesheet" href="/css/style.css">
  <link rel="stylesheet" href="/font-awesome/css/font-awesome.min.css">
  <link rel="apple-touch-icon" href="/apple-touch-icon.png">
  
  
      <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
  
  <!-- 加载特效 -->
    <script src="/js/pace.js"></script>
    <link href="/css/pace/pace-theme-flash.css" rel="stylesheet" />
  <script>
      var yiliaConfig = {
          rootUrl: '/',
          fancybox: true,
          animate: true,
          isHome: false,
          isPost: true,
          isArchive: false,
          isTag: false,
          isCategory: false,
          open_in_new: false
      }
  </script>
</head>
<body>
  <div id="container">
    <div class="left-col">
    <div class="overlay"></div>
<div class="intrude-less">
    <header id="header" class="inner">
        <a href="/" class="profilepic">
            
            <img lazy-src="/img/head.jpg" class="js-avatar">
            
        </a>

        <hgroup>
          <h1 class="header-author"><a href="/" title="Hi Mate">安与生</a></h1>
        </hgroup>

        
        <p class="header-subtitle">城已成，兵不封，鼓不停，志不移，行不息</p>
        
        
            <form>
                <input type="text" class="st-default-search-input search" id="search" placeholder=" Search...">
            </form>
        
        
            <div id="switch-btn" class="switch-btn">
                <div class="icon">
                    <div class="icon-ctn">
                        <div class="icon-wrap icon-house" data-idx="0">
                            <div class="birdhouse"></div>
                            <div class="birdhouse_holes"></div>
                        </div>
                        <div class="icon-wrap icon-ribbon hide" data-idx="1">
                            <div class="ribbon"></div>
                        </div>
                        
                        <div class="icon-wrap icon-link hide" data-idx="2">
                            <div class="loopback_l"></div>
                            <div class="loopback_r"></div>
                        </div>
                        
                        
                        <div class="icon-wrap icon-me hide" data-idx="3">
                            <div class="user"></div>
                            <div class="shoulder"></div>
                        </div>
                        
                    </div>
                    
                </div>
                <div class="tips-box hide">
                    <div class="tips-arrow"></div>
                    <ul class="tips-inner">
                        <li>菜单</li>
                        <li>标签</li>
                        
                        <li>友情链接</li>
                        
                        
                        <li>关于我</li>
                        
                    </ul>
                </div>
            </div>
        

        <div id="switch-area" class="switch-area">
            <div class="switch-wrap">
                <section class="switch-part switch-part1">
                    <nav class="header-menu">
                        <ul>
                        
                            <li><a href="/archives">所有文章</a></li>
                        
                            <li><a href="/works">作品展示</a></li>
                        
                           <li><a href="/about">留言打卡</a></li>
                        
                            <li><a  target="_blank" href="https://tuchong.com/1496450/">摄影集展示</a></li>
                        
                        </ul>
                    </nav>
                    <nav class="header-nav">
                        <ul class="social">
                            
                                <a class="fl mail" target="_blank" href="http://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&email=4trX0tXT19PV1aKTk8yBjY8" title="mail">mail</a>
                            
                                <a class="fl github" target="_blank" href="https://github.com/Jimmey-Jiang" title="github">github</a>
                            
                                <a class="fl zhihu" target="_blank" href="https://www.zhihu.com" title="zhihu">zhihu</a>
                            
                                <a class="fl weibo" target="_blank" href="http://weibo.com" title="weibo">weibo</a>
                            
                                <a class="fl google" target="_blank" href="http://i.youku.com" title="google">google</a>
                            
                                <a class="fl twitter" target="_blank" href="http://twitter.com" title="twitter">twitter</a>
                            
                                <a class="fl Instagram" target="_blank" href="https://www.instagram.com" title="Instagram">Instagram</a>
                            
                                <a class="fl linkedin" target="_blank" href="https://www.linkedin.com" title="linkedin">linkedin</a>
                            
                        </ul>
                    </nav>
                </section>
                
                
                <section class="switch-part switch-part2">
                    <div class="widget tagcloud" id="js-tagcloud">
                        <a href="/tags/Ajax/" style="font-size: 11.67px;">Ajax</a> <a href="/tags/CDN/" style="font-size: 10px;">CDN</a> <a href="/tags/CSS/" style="font-size: 18.33px;">CSS</a> <a href="/tags/CSS3/" style="font-size: 11.67px;">CSS3</a> <a href="/tags/Chrome/" style="font-size: 10px;">Chrome</a> <a href="/tags/Development/" style="font-size: 10px;">Development</a> <a href="/tags/Front-end-outline/" style="font-size: 10px;">Front end outline</a> <a href="/tags/FrontPlan/" style="font-size: 10px;">FrontPlan</a> <a href="/tags/Git/" style="font-size: 11.67px;">Git</a> <a href="/tags/Gulp/" style="font-size: 10px;">Gulp</a> <a href="/tags/HTML/" style="font-size: 13.33px;">HTML</a> <a href="/tags/Hack/" style="font-size: 10px;">Hack</a> <a href="/tags/Hexo/" style="font-size: 16.67px;">Hexo</a> <a href="/tags/Interview/" style="font-size: 10px;">Interview</a> <a href="/tags/JavaScript/" style="font-size: 13.33px;">JavaScript</a> <a href="/tags/Javascript/" style="font-size: 10px;">Javascript</a> <a href="/tags/Markdown/" style="font-size: 10px;">Markdown</a> <a href="/tags/Mobile/" style="font-size: 13.33px;">Mobile</a> <a href="/tags/NodeJs/" style="font-size: 10px;">NodeJs</a> <a href="/tags/OOCSS/" style="font-size: 10px;">OOCSS</a> <a href="/tags/React/" style="font-size: 10px;">React</a> <a href="/tags/ReactNative/" style="font-size: 20px;">ReactNative</a> <a href="/tags/Sass/" style="font-size: 10px;">Sass</a> <a href="/tags/Sublime/" style="font-size: 15px;">Sublime</a> <a href="/tags/Terminal/" style="font-size: 10px;">Terminal</a> <a href="/tags/Video/" style="font-size: 10px;">Video</a> <a href="/tags/Vue/" style="font-size: 15px;">Vue</a> <a href="/tags/WeChatSDK/" style="font-size: 10px;">WeChatSDK</a> <a href="/tags/rem/" style="font-size: 10px;">rem</a> <a href="/tags/window-7/" style="font-size: 10px;">window 7</a>
                    </div>
                </section>
                
                
                
                <section class="switch-part switch-part3">
                    <div id="js-friends">
                    
                      <a target="_blank" class="main-nav-link switch-friends-link" href="http://MOxFIVE.github.io/">MOxFIVE</a>
                    
                      <a target="_blank" class="main-nav-link switch-friends-link" href="http://www.vsay.cn/">DoubleV</a>
                    
                      <a target="_blank" class="main-nav-link switch-friends-link" href="http://www.ccwebsite.com/">兮兮</a>
                    
                      <a target="_blank" class="main-nav-link switch-friends-link" href="http://blog.dandyweng.com/">翁天信</a>
                    
                      <a target="_blank" class="main-nav-link switch-friends-link" href="http://www.plqblog.com/views/index.php">潘利强</a>
                    
                      <a target="_blank" class="main-nav-link switch-friends-link" href="http://www.hankin.cn/">hankin</a>
                    
                      <a target="_blank" class="main-nav-link switch-friends-link" href="http://blog.waydrow.com/">waydrow</a>
                    
                      <a target="_blank" class="main-nav-link switch-friends-link" href="https://www.tangbc.com">TANGBC</a>
                    
                      <a target="_blank" class="main-nav-link switch-friends-link" href="https://www.w3ctrain.com/">Helkyle</a>
                    
                    </div>
                </section>
                

                
                
                <section class="switch-part switch-part4">
                
                    <div id="js-aboutme">城已成，兵不封，鼓不停，志不移，行不息</div>
                </section>
                
            </div>
        </div>
    </header>                
</div>
    </div>
    <div class="mid-col">
      <nav id="mobile-nav">
      <div class="overlay">
          <div class="slider-trigger"></div>
          <h1 class="header-author js-mobile-header hide"><a href="/" title="Me">安与生</a></h1>
      </div>
    <div class="intrude-less">
        <header id="header" class="inner">
            <a href="/" class="profilepic">
                
                    <img lazy-src="/img/head.jpg" class="js-avatar">
                
            </a>
            <hgroup>
              <h1 class="header-author"><a href="/" title="Me">安与生</a></h1>
            </hgroup>
            
            <p class="header-subtitle">城已成，兵不封，鼓不停，志不移，行不息</p>
            
            <nav class="header-menu">
                <ul>
                
                    <li><a href="/archives">所有文章</a></li>
                
                    <li><a href="/works">作品展示</a></li>
                
                   <li><a href="/about">留言打卡</a></li>
                
                    <li><a  target="_blank" href="https://tuchong.com/1496450/">摄影集展示</a></li>
                
                <div class="clearfix"></div>
                </ul>
            </nav>
            <nav class="header-nav">
                <div class="social">
                    
                        <a class="mail" target="_blank" href="http://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&email=4trX0tXT19PV1aKTk8yBjY8" title="mail">mail</a>
                    
                        <a class="github" target="_blank" href="https://github.com/Jimmey-Jiang" title="github">github</a>
                    
                        <a class="zhihu" target="_blank" href="https://www.zhihu.com" title="zhihu">zhihu</a>
                    
                        <a class="weibo" target="_blank" href="http://weibo.com" title="weibo">weibo</a>
                    
                        <a class="google" target="_blank" href="http://i.youku.com" title="google">google</a>
                    
                        <a class="twitter" target="_blank" href="http://twitter.com" title="twitter">twitter</a>
                    
                        <a class="Instagram" target="_blank" href="https://www.instagram.com" title="Instagram">Instagram</a>
                    
                        <a class="linkedin" target="_blank" href="https://www.linkedin.com" title="linkedin">linkedin</a>
                    
                </div>
            </nav>
        </header>                
    </div>
</nav>
      <div class="body-wrap"><article id="post-Tool/Git" class="article article-type-post" itemscope itemprop="blogPost">
  
    <div class="article-meta">
      <a href="/2017/08/19/Tool/Git/" class="article-date">
      <time datetime="2017-08-19T06:11:20.000Z" itemprop="datePublished">2017-08-19</time>
</a>
    </div>
  
  <div class="article-inner">
    
      <input type="hidden" class="isFancy" />
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      Git速查手册
    </h1>
  

      </header>
      
      <div class="article-info article-info-post">
        
    <div class="article-category tagcloud">
    <a class="article-category-link" href="/categories/Tool/">Tool</a>
    </div>

        
    <div class="article-tag tagcloud">
        <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Git/">Git</a></li></ul>
    </div>

        <div class="clearfix"></div>
      </div>
      
    
    <div class="article-entry" itemprop="articleBody">
      
          
        <h1 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h1><h2 id="Linux"><a href="#Linux" class="headerlink" title="Linux"></a>Linux</h2><p>打开控制台，然后通过包管理安装，在Ubuntu上命令是：<br><figure class="highlight q"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">sudo apt-<span class="built_in">get</span> install git-<span class="built_in">all</span></div></pre></td></tr></table></figure></p>
<h2 id="Windows"><a href="#Windows" class="headerlink" title="Windows"></a>Windows</h2><p>推荐使用git for<br>windows，它包括了图形工具以及命令行模拟器。</p>
<h2 id="OS-X"><a href="#OS-X" class="headerlink" title="OS X"></a>OS X</h2><p>最简单的方式是使用homebrew安装，命令行执行<br><figure class="highlight mipsasm"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">brew </span><span class="keyword">install </span>git</div></pre></td></tr></table></figure></p>
<p>如果你是在是先用图形工具的话，那么推荐你使用Github desktop,Sourcetree。但我还是推荐你使用命令行，下面的内容就都是命令行的。<br><a id="more"></a></p>
<ul>
<li><a href="&quot;&quot;"></a></li>
<li><a href="&quot;&quot;"></a></li>
<li><a href="&quot;&quot;"></a></li>
<li><a href="&quot;&quot;"></a></li>
<li><a href="&quot;&quot;"></a></li>
</ul>
<h1 id="Git-术语"><a href="#Git-术语" class="headerlink" title="Git 术语"></a>Git 术语</h1><table>
<thead>
<tr>
<th>术语</th>
<th>定义</th>
</tr>
</thead>
<tbody>
<tr>
<td>仓库（Repository）</td>
<td>一个仓库包括了所有的版本信息、所有的分支和标记信息。在Git中仓库的每份拷贝都是完整的。仓库让你可以从中取得你的工作副本。</td>
</tr>
<tr>
<td>分支（Branches）</td>
<td>一个分支意味着一个独立的、拥有自己历史信息的代码线（code line）。你可以从已有的代码中生成一个新的分支，这个分支与剩余的分支完全独立。默认的分支往往是叫master。用户可以选择一个分支，选择一个分支执行命令git checkout branch.</td>
</tr>
<tr>
<td>标记（Tags）</td>
<td>一个标记指的是某个分支某个特定时间点的状态。通过标记，可以很方便的切换到标记时的状态，例如2009年1月25号在testing分支上的代码状态</td>
</tr>
<tr>
<td>提交（Commit）</td>
<td>提交代码后，仓库会创建一个新的版本。这个版本可以在后续被重新获得。每次提交都包括作者和提交者，作者和提交者可以是不同的人</td>
</tr>
<tr>
<td>修订（Revision）</td>
<td>用来表示代码的一个版本状态。Git通过用SHA1 hash算法表示的id来标识不同的版本。每一个 SHA1 id都是160位长，16进制标识的字符串.。最新的版本可以通过HEAD来获取。之前的版本可以通过”HEAD~1”来获取，以此类推。</td>
</tr>
</tbody>
</table>
<h1 id="创建"><a href="#创建" class="headerlink" title="创建"></a>创建</h1><h2 id="新建仓库"><a href="#新建仓库" class="headerlink" title="新建仓库"></a>新建仓库</h2><figure class="highlight xml"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line"><span class="comment">&lt;!-- 在当前目录新建一个Git代码库 --&gt;</span></div><div class="line">$ git init</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 新建一个目录，将其初始化为Git代码库 --&gt;</span></div><div class="line">$ git init [project-name]</div></pre></td></tr></table></figure>
<h2 id="复制远程仓库"><a href="#复制远程仓库" class="headerlink" title="复制远程仓库"></a>复制远程仓库</h2><figure class="highlight xml"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"><span class="comment">&lt;!-- 下载一个项目和它的整个代码历史 --&gt;</span></div><div class="line">$ git clone [url]</div></pre></td></tr></table></figure>
<h1 id="配置"><a href="#配置" class="headerlink" title="配置"></a>配置</h1><h2 id="配置账号信息"><a href="#配置账号信息" class="headerlink" title="配置账号信息"></a>配置账号信息</h2><p>Git的设置文件为.gitconfig，它可以在用户主目录下（全局配置），也可以在项目目录下（项目配置）。<br><figure class="highlight routeros"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">&lt;!-- 设置提交代码时的用户信息 --&gt;</div><div class="line">$ git<span class="built_in"> config </span>--global user.name <span class="string">"My Name"</span></div><div class="line">$ git<span class="built_in"> config </span>--global user.email myEmail@example.com</div><div class="line"></div><div class="line">&lt;!-- 显示仓库的Git配置 --&gt;</div><div class="line">$ git<span class="built_in"> config </span>--list</div><div class="line"></div><div class="line">&lt;!-- 编辑Git配置文件 --&gt;</div><div class="line">$ git<span class="built_in"> config </span>-e [--global]</div></pre></td></tr></table></figure></p>
<p>配置好这两项，用户就能知道谁做了什么，并且一切都更有组织性了不是吗？</p>
<h3 id="生成SSH秘钥"><a href="#生成SSH秘钥" class="headerlink" title="生成SSH秘钥"></a>生成SSH秘钥</h3><p>用于上传到你对应的github账号<br><figure class="highlight xml"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">$ ssh-keygen -t rsa -C "mail@gmail.com"</div><div class="line"><span class="comment">&lt;!-- 这的密码不是我们GitHub的密码，而是Git SSH的密码 --&gt;</span></div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 打开Git生成的密码文件，将其复制到GitHub上 --&gt;</span></div><div class="line">$ vim ~/.ssh/id_rsa.pub</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 验证GitHub SSH是否成功 --&gt;</span></div><div class="line">$ ssh -T git@github.com</div></pre></td></tr></table></figure></p>
<h1 id="案例"><a href="#案例" class="headerlink" title="案例"></a>案例</h1><h2 id="提交流程"><a href="#提交流程" class="headerlink" title="提交流程"></a>提交流程</h2><p><img src="http://img.blog.csdn.net/20161219162011600?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxNDM0NjMwMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="提交流程"></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line"><span class="meta">$</span><span class="bash"> git pull</span></div><div class="line"><span class="meta">$</span><span class="bash"> git start</span></div><div class="line"><span class="meta">$</span><span class="bash"> git add</span></div><div class="line"><span class="meta">$</span><span class="bash"> git commit -m <span class="string">""</span></span></div><div class="line"><span class="meta">$</span><span class="bash"> git push</span></div></pre></td></tr></table></figure>
<h1 id="修改与提交"><a href="#修改与提交" class="headerlink" title="修改与提交"></a>修改与提交</h1><h2 id="修改"><a href="#修改" class="headerlink" title="修改"></a>修改</h2><figure class="highlight xml"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div></pre></td><td class="code"><pre><div class="line"><span class="comment">&lt;!-- 添加指定文件到暂存区 --&gt;</span></div><div class="line">$ git add [file1] [file2] ...</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 添加指定目录到暂存区，包括子目录 --&gt;</span></div><div class="line">$ git add [dir]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 添加当前目录的所有文件到暂存区 --&gt;</span></div><div class="line">$ git add .</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 添加每个变化前，都会要求确认 --&gt;</span></div><div class="line"><span class="comment">&lt;!-- 对于同一个文件的多处变化，可以实现分次提交 --&gt;</span></div><div class="line">$ git add -p</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 删除工作区文件，并且将这次删除放入暂存区 --&gt;</span></div><div class="line">$ git rm [file1] [file2] </div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 停止追踪指定文件，但该文件会保留在工作区 --&gt;</span></div><div class="line">$ git rm --cached [file]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 改名文件，并且将这个改名放入暂存区 --&gt;</span></div><div class="line">$ git mv [file-original] [file-renamed]</div></pre></td></tr></table></figure>
<h2 id="提交"><a href="#提交" class="headerlink" title="提交"></a>提交</h2><figure class="highlight xml"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div></pre></td><td class="code"><pre><div class="line"><span class="comment">&lt;!-- 提交暂存区到仓库区 --&gt;</span></div><div class="line">$ git commit -m [message]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 提交暂存区的指定文件到仓库区 --&gt;</span></div><div class="line">$ git commit [file1] [file2] ... -m [message]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 提交工作区自上次commit之后的变化，直接到仓库区 --&gt;</span></div><div class="line">$ git commit -a</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 提交时显示所有diff信息 --&gt;</span></div><div class="line">$ git commit -v</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 使用一次新的commit，替代上一次提交 --&gt;</span></div><div class="line"><span class="comment">&lt;!-- 如果代码没有任何新变化，则用来改写上一次commit的提交信息 --&gt;</span></div><div class="line">$ git commit --amend -m [message]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 重做上一次commit，并包括指定文件的新变化 --&gt;</span></div><div class="line">$ git commit --amend [file1] [file2]</div></pre></td></tr></table></figure>
<h1 id="分支与标签"><a href="#分支与标签" class="headerlink" title="分支与标签"></a>分支与标签</h1><h2 id="分支"><a href="#分支" class="headerlink" title="分支"></a>分支</h2><figure class="highlight xml"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div></pre></td><td class="code"><pre><div class="line"><span class="comment">&lt;!-- 列出所有本地分支 --&gt;</span></div><div class="line">$ git branch</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 列出所有远程分支 --&gt;</span></div><div class="line">$ git branch -r</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 列出所有本地分支和远程分支 --&gt;</span></div><div class="line">$ git branch -a</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 新建一个分支，但依然停留在当前分支 --&gt;</span></div><div class="line">$ git branch [branch-name]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 新建一个分支，并切换到该分支 --&gt;</span></div><div class="line">$ git checkout -b [branch]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 新建一个分支，指向指定commit --&gt;</span></div><div class="line">$ git branch [branch] [commit]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 新建一个分支，与指定的远程分支建立追踪关系 --&gt;</span></div><div class="line">$ git branch --track [branch] [remote-branch]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 切换到指定分支，并更新工作区 --&gt;</span></div><div class="line">$ git checkout [branch-name]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 切换到上一个分支 --&gt;</span></div><div class="line">$ git checkout -</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 建立追踪关系，在现有分支与指定的远程分支之间 --&gt;</span></div><div class="line">$ git branch --set-upstream [branch] [remote-branch]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 合并指定分支到当前分支 --&gt;</span></div><div class="line">$ git merge [branch]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 选择一个commit，合并进当前分支 --&gt;</span></div><div class="line">$ git cherry-pick [commit]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 删除分支 --&gt;</span></div><div class="line">$ git branch -d [branch-name]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 删除远程分支 --&gt;</span></div><div class="line">$ git push origin --delete [branch-name]</div><div class="line">$ git branch -dr [remote/branch]</div></pre></td></tr></table></figure>
<h2 id="标签"><a href="#标签" class="headerlink" title="标签"></a>标签</h2><figure class="highlight xml"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div></pre></td><td class="code"><pre><div class="line"><span class="comment">&lt;!-- 列出所有tag --&gt;</span></div><div class="line">$ git tag</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 新建一个tag在当前commit --&gt;</span></div><div class="line">$ git tag [tag]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 新建一个tag在指定commit --&gt;</span></div><div class="line">$ git tag [tag] [commit]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 删除本地tag --&gt;</span></div><div class="line">$ git tag -d [tag]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 删除远程tag --&gt;</span></div><div class="line">$ git push origin :refs/tags/[tagName]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 查看tag信息 --&gt;</span></div><div class="line">$ git show [tag]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 提交指定tag --&gt;</span></div><div class="line">$ git push [remote] [tag]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 提交所有tag --&gt;</span></div><div class="line">$ git push [remote] --tags</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 新建一个分支，指向某个tag --&gt;</span></div><div class="line">$ git checkout -b [branch] [tag]</div></pre></td></tr></table></figure>
<h1 id="查看信息"><a href="#查看信息" class="headerlink" title="查看信息"></a>查看信息</h1><figure class="highlight dust"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div></pre></td><td class="code"><pre><div class="line"><span class="xml"><span class="comment">&lt;!-- 显示有变更的文件 --&gt;</span></span></div><div class="line">$ git status</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 显示当前分支的版本历史 --&gt;</span></div><div class="line">$ git log</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 显示commit历史，以及每次commit发生变更的文件 --&gt;</span></div><div class="line">$ git log --stat</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 搜索提交历史，根据关键词 --&gt;</span></div><div class="line">$ git log -S [keyword]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 显示某个commit之后的所有变动，每个commit占据一行 --&gt;</span></div><div class="line">$ git log [tag] HEAD --pretty=format:%s</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 显示某个commit之后的所有变动，其"提交说明"必须符合搜索条件 --&gt;</span></div><div class="line">$ git log [tag] HEAD --grep feature</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 显示某个文件的版本历史，包括文件改名 --&gt;</span></div><div class="line">$ git log --follow [file]</div><div class="line">$ git whatchanged [file]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 显示指定文件相关的每一次diff --&gt;</span></div><div class="line">$ git log -p [file]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 显示1行日志 -n为n行  --&gt;</span></div><div class="line">$ git log -5</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 显示过去5次提交 --&gt;</span></div><div class="line">$ git log -5 --pretty --oneline</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 显示所有提交过的用户，按提交次数排序 --&gt;</span></div><div class="line">$ git shortlog -sn</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 显示指定文件是什么人在什么时间修改过 --&gt;</span></div><div class="line">$ git blame [file]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 显示暂存区和工作区的差异 --&gt;</span></div><div class="line">$ git diff</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 显示暂存区和上一个commit的差异 --&gt;</span></div><div class="line">$ git diff --cached [file]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 显示工作区与当前分支最新commit之间的差异 --&gt;</span></div><div class="line">$ git diff HEAD</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 显示两次提交之间的差异 --&gt;</span></div><div class="line">$ git diff [first-branch]...[second-branch]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 显示今天你写了多少行代码 --&gt;</span></div><div class="line">$ git diff --shortstat "@<span class="template-variable">&#123;0 day ago&#125;</span><span class="xml">"</span></div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 显示某次提交的元数据和内容变化 --&gt;</span></div><div class="line">$ git show [commit]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 显示某次提交发生变化的文件 --&gt;</span></div><div class="line">$ git show --name-only [commit]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 显示某次提交时，某个文件的内容 --&gt;</span></div><div class="line">$ git show [commit]:[filename]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 显示当前分支的最近几次提交 --&gt;</span></div><div class="line">$ git reflog</div></pre></td></tr></table></figure>
<h1 id="远程同步"><a href="#远程同步" class="headerlink" title="远程同步"></a>远程同步</h1><figure class="highlight xml"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div></pre></td><td class="code"><pre><div class="line"><span class="comment">&lt;!-- 下载远程仓库的所有变动 --&gt;</span></div><div class="line">$ git fetch [remote]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 显示所有远程仓库 --&gt;</span></div><div class="line">$ git remote -v</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 显示某个远程仓库的信息 --&gt;</span></div><div class="line">$ git remote show [remote]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 增加一个新的远程仓库，并命名 --&gt;</span></div><div class="line">$ git remote add [shortname] [url]</div><div class="line"></div><div class="line">git pull <span class="tag">&lt;<span class="name">远程主机名(origin)</span>&gt;</span> <span class="tag">&lt;<span class="name">远程分支名</span>&gt;</span>:<span class="tag">&lt;<span class="name">本地分支名</span>&gt;</span></div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 取回远程仓库的变化，并与本地分支合并 --&gt;</span></div><div class="line">$ git pull [remote] [branch]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 上传本地指定分支到远程仓库 --&gt;</span></div><div class="line">$ git push [remote] [branch]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 强行推送当前分支到远程仓库，即使有冲突 --&gt;</span></div><div class="line">$ git push [remote] --force</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 推送所有分支到远程仓库 --&gt;</span></div><div class="line">$ git push [remote] --all</div></pre></td></tr></table></figure>
<h1 id="撤销"><a href="#撤销" class="headerlink" title="撤销"></a>撤销</h1><figure class="highlight xml"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div></pre></td><td class="code"><pre><div class="line"><span class="comment">&lt;!-- 恢复暂存区的指定文件到工作区 --&gt;</span></div><div class="line">$ git checkout [file]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 恢复某个commit的指定文件到暂存区和工作区 --&gt;</span></div><div class="line">$ git checkout [commit] [file]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 恢复暂存区的所有文件到工作区 --&gt;</span></div><div class="line">$ git checkout .</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 重置暂存区的指定文件，与上一次commit保持一致，但工作区不变 --&gt;</span></div><div class="line">$ git reset [file]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 重置暂存区与工作区，与上一次commit保持一致 --&gt;</span></div><div class="line">$ git reset --hard</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 重置当前分支的指针为指定commit，同时重置暂存区，但工作区不变 --&gt;</span></div><div class="line">$ git reset [commit]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 重置当前分支的HEAD为指定commit，同时重置暂存区和工作区，与指定commit一致 --&gt;</span></div><div class="line">$ git reset --hard [commit]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 重置当前HEAD为指定commit，但保持暂存区和工作区不变 --&gt;</span></div><div class="line">$ git reset --keep [commit]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 新建一个commit，用来撤销指定commit --&gt;</span></div><div class="line"><span class="comment">&lt;!-- 后者的所有变化都将被前者抵消，并且应用到当前分支 --&gt;</span></div><div class="line">$ git revert [commit]</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- 暂时将未提交的变化移除，稍后再移入 --&gt;</span></div><div class="line">$ git stash</div><div class="line">$ git stash pop</div></pre></td></tr></table></figure>
<h1 id="其他"><a href="#其他" class="headerlink" title="其他"></a>其他</h1><figure class="highlight xml"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"><span class="comment">&lt;!-- 生成一个可供发布的压缩包 --&gt;</span></div><div class="line">$ git archive</div></pre></td></tr></table></figure>
<h1 id="拓展"><a href="#拓展" class="headerlink" title="拓展"></a>拓展</h1><ul>
<li><a href="https://github.com/xirong/my-git" title="有关 git 的学习资料" target="_blank" rel="external">my-git</a></li>
<li><a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000" title="讲解过于复杂，而且还有很多广告" target="_blank" rel="external">廖雪峰Git教程</a></li>
<li><a href="http://jlord.us/git-it/" title="一位女员工写的 Git 教程" target="_blank" rel="external">Git-it - GitHub</a></li>
<li><a href="http://learngitbranching.js.org/?demo" title="是一个git仿真沙盒" target="_blank" rel="external">Learn Git Branching</a></li>
<li><a href="http://www.jianshu.com/p/da9bc509b1d2" target="_blank" rel="external">github快速入门</a></li>
<li><a href="http://rogerdudler.github.io/git-guide/index.zh.html" target="_blank" rel="external">git - 简明指南</a></li>
<li><a href="https://aotu.io/notes/2017/04/10/githooks/" target="_blank" rel="external">用 Git 钩子进行简单自动部署</a></li>
<li><a href="https://github.com/geeeeeeeeek/git-recipes/wiki" target="_blank" rel="external">git-recipes</a></li>
<li><a href="http://www.ui.cn/detail/20957.html" target="_blank" rel="external">专为设计师而写的GitHub快速入门教程</a></li>
<li><a href="&quot;&quot;"></a></li>
<li><a href="&quot;&quot;"></a></li>
<li><a href="&quot;&quot;"></a></li>
</ul>
<h2 id="工作流"><a href="#工作流" class="headerlink" title="工作流"></a>工作流</h2><ul>
<li><a href="https://juejin.im/search?query=Git%20%E5%B7%A5%E4%BD%9C%E6%B5%81" target="_blank" rel="external">Git 工作流</a></li>
<li><a href="https://www.atlassian.com/git/tutorials/comparing-workflows" target="_blank" rel="external">Comparing Workflows</a></li>
<li><a href="http://blog.jobbole.com/76867/#comment-156726" target="_blank" rel="external">Git工作流指南：Gitflow工作流</a></li>
<li><a href="http://nvie.com/posts/a-successful-git-branching-model/" target="_blank" rel="external">A successful Git branching model</a></li>
<li><a href="https://tech.meituan.com/improving-git-flow_squashing-commits.html" target="_blank" rel="external">改进合作 Git 工作流：自动提取、合并提交</a></li>
</ul>
<h2 id="速查表"><a href="#速查表" class="headerlink" title="速查表"></a>速查表</h2><ul>
<li><a href="http://backlogtool.com/git-guide/cn/reference/" target="_blank" rel="external">Git索引</a></li>
<li><a href="https://www.git-tower.com/blog/git-cheat-sheet-cn" target="_blank" rel="external">Git指令速查表</a></li>
</ul>
<h2 id="图解"><a href="#图解" class="headerlink" title="图解"></a>图解</h2><ul>
<li><a href="http://backlogtool.com/git-guide/cn/" target="_blank" rel="external">猴子都能懂的Git入门</a></li>
<li><a href="http://marklodato.github.io/visual-git-guide/index-zh-cn.html#conventions" target="_blank" rel="external">图解Git</a></li>
</ul>

      
      
        <div class="page-reward">
          <p><a href="javascript:void(0)" onclick="dashangToggle()" class="dashang">赏</a></p>
          <div class="hide_box"></div>
          <div class="shang_box">
            <a class="shang_close" href="javascript:void(0)" onclick="dashangToggle()">×</a>
            <div class="shang_tit">
              <p>纯属好玩</p>
            </div>
            <div class="shang_payimg">
              <img src="/img/alipayimg.jpg" alt="扫码支持" title="扫一扫" />
            </div>
              <div class="pay_explain">扫码打赏，你说多少就多少</div>
            <div class="shang_payselect">
              
                <div class="pay_item checked" data-id="alipay">
                  <span class="radiobox"></span>
                  <span class="pay_logo"><img src="/img/alipay.png" alt="支付宝" /></span>
                </div>
              
              
                <div class="pay_item" data-id="wechat">
                  <span class="radiobox"></span>
                  <span class="pay_logo"><img src="/img/weixin.png" alt="微信" /></span>
                </div>
              
            </div>
            <div class="shang_info">
              <p>打开<span id="shang_pay_txt">支付宝</span>扫一扫，即可进行扫码打赏哦</p>
            </div>
          </div>
        </div>
        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/zepto/1.2.0/zepto.min.js"></script>
        <script type="text/javascript">
          $(".pay_item").click(function(){
            $(this).addClass('checked').siblings('.pay_item').removeClass('checked');
            var dataid=$(this).attr('data-id');
            $(".shang_payimg img").attr("src","/img/"+dataid+"img.jpg");
            $("#shang_pay_txt").text(dataid=="alipay"?"支付宝":"微信");
          });
          function dashangToggle(){
            window._hmt.push(['_trackEvent', 'pay', 'click', '赏'])
            $(".hide_box").fadeToggle();
            $(".shang_box").fadeToggle();
          }
        </script>
      
    </div>
    
  </div>
  
    
    <div class="copyright">
        <p><span>本文标题:</span><a href="/2017/08/19/Tool/Git/">Git速查手册</a></p>
        <p><span>文章作者:</span><a href="/" title="访问 安与生 的个人博客">安与生</a></p>
        <p><span>发布时间:</span>2017年08月19日 - 14时11分</p>
        <p><span>最后更新:</span>2017年08月16日 - 13时15分</p>
        <p>
            <span>原始链接:</span><a class="post-url" href="/2017/08/19/Tool/Git/" title="Git速查手册">http://Jimmey-Jiang.github.io/2017/08/19/Tool/Git/</a>
            <span class="copy-path" data-clipboard-text="原文: http://Jimmey-Jiang.github.io/2017/08/19/Tool/Git/　　作者: 安与生" title="点击复制文章链接"><i class="fa fa-clipboard"></i></span>
            <script src="/js/clipboard.min.js"></script>
            <script> var clipboard = new Clipboard('.copy-path'); </script>
        </p>
        <p>
            <span>许可协议:</span><i class="fa fa-creative-commons"></i> <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/cn/" title="中国大陆 (CC BY-NC-SA 3.0 CN)" target = "_blank">"署名-非商用-相同方式共享 3.0"</a> 转载请保留原文链接及作者。
        </p>
    </div>



<nav id="article-nav">
  
    <a href="/2017/08/29/Tool/GitWorkflows/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption"><</strong>
      <div class="article-nav-title">
        
          Git Workflows
        
      </div>
    </a>
  
  
    <a href="/2017/08/18/FrontFrame/Vue/VueComponents/" id="article-nav-older" class="article-nav-link-wrap">
      <div class="article-nav-title">Vue组件探秘</div>
      <strong class="article-nav-caption">></strong>
    </a>
  
</nav>

  
</article>

    <div id="toc" class="toc-article">
    <strong class="toc-title">文章目录</strong>
    <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#安装"><span class="toc-number">1.</span> <span class="toc-text">安装</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#Linux"><span class="toc-number">1.1.</span> <span class="toc-text">Linux</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Windows"><span class="toc-number">1.2.</span> <span class="toc-text">Windows</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#OS-X"><span class="toc-number">1.3.</span> <span class="toc-text">OS X</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Git-术语"><span class="toc-number">2.</span> <span class="toc-text">Git 术语</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#创建"><span class="toc-number">3.</span> <span class="toc-text">创建</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#新建仓库"><span class="toc-number">3.1.</span> <span class="toc-text">新建仓库</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#复制远程仓库"><span class="toc-number">3.2.</span> <span class="toc-text">复制远程仓库</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#配置"><span class="toc-number">4.</span> <span class="toc-text">配置</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#配置账号信息"><span class="toc-number">4.1.</span> <span class="toc-text">配置账号信息</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#生成SSH秘钥"><span class="toc-number">4.1.1.</span> <span class="toc-text">生成SSH秘钥</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#案例"><span class="toc-number">5.</span> <span class="toc-text">案例</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#提交流程"><span class="toc-number">5.1.</span> <span class="toc-text">提交流程</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#修改与提交"><span class="toc-number">6.</span> <span class="toc-text">修改与提交</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#修改"><span class="toc-number">6.1.</span> <span class="toc-text">修改</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#提交"><span class="toc-number">6.2.</span> <span class="toc-text">提交</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#分支与标签"><span class="toc-number">7.</span> <span class="toc-text">分支与标签</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#分支"><span class="toc-number">7.1.</span> <span class="toc-text">分支</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#标签"><span class="toc-number">7.2.</span> <span class="toc-text">标签</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#查看信息"><span class="toc-number">8.</span> <span class="toc-text">查看信息</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#远程同步"><span class="toc-number">9.</span> <span class="toc-text">远程同步</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#撤销"><span class="toc-number">10.</span> <span class="toc-text">撤销</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#其他"><span class="toc-number">11.</span> <span class="toc-text">其他</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#拓展"><span class="toc-number">12.</span> <span class="toc-text">拓展</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#工作流"><span class="toc-number">12.1.</span> <span class="toc-text">工作流</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#速查表"><span class="toc-number">12.2.</span> <span class="toc-text">速查表</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#图解"><span class="toc-number">12.3.</span> <span class="toc-text">图解</span></a></li></ol></li></ol>
</div>
<input type="button" id="tocButton" value="隐藏目录"  title="点击按钮隐藏或者显示文章目录">

<script src="https://7.url.cn/edu/jslib/comb/require-2.1.6,jquery-1.9.1.min.js"></script>
<script>
    var valueHide = "隐藏目录";
    var valueShow = "显示目录";

    if ($(".left-col").is(":hidden")) {
        $("#tocButton").attr("value", valueShow);
    }
    $("#tocButton").click(function() {
        if ($("#toc").is(":hidden")) {
            $("#tocButton").attr("value", valueHide);
            $("#toc").slideDown(320);
        }
        else {
            $("#tocButton").attr("value", valueShow);
            $("#toc").slideUp(350);
        }
    })
    if ($(".toc").length < 1) {
        $("#toc, #tocButton").hide();
    }
</script>





<div class="bdsharebuttonbox">
	<a href="#" class="fx fa-weibo bds_tsina" data-cmd="tsina" title="分享到新浪微博"></a>
	<a href="#" class="fx fa-weixin bds_weixin" data-cmd="weixin" title="分享到微信"></a>
	<a href="#" class="fx fa-qq bds_sqq" data-cmd="sqq" title="分享到QQ好友"></a>
	<a href="#" class="fx fa-facebook-official bds_fbook" data-cmd="fbook" title="分享到Facebook"></a>
	<a href="#" class="fx fa-twitter bds_twi" data-cmd="twi" title="分享到Twitter"></a>
	<a href="#" class="fx fa-linkedin bds_linkedin" data-cmd="linkedin" title="分享到linkedin"></a>
	<a href="#" class="fx fa-files-o bds_copy" data-cmd="copy" title="分享到复制网址"></a>
</div>
<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"2","bdSize":"24"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>




    
        <div id="gitments"></div>
<script src="/js/gitment.browser.js"></script>
<script>
    var gitment = new Gitment({
      id: window.location.pathname,
      owner: 'Jimmey-Jiang',
      repo: 'Jimmey-Jiang.github.io',
      oauth: {
        client_id: '7f50019c6a02c37e7aca',
        client_secret: 'd583910e6ae1492b375796d2c82efcda2cc67aae',
      },
    })
    gitment.render('gitments')
</script>
    



    <div class="scroll" id="post-nav-button">
        
            <a href="/2017/08/29/Tool/GitWorkflows/" title="上一篇: Git Workflows">
                <i class="fa fa-angle-left"></i>
            </a>
        
        <a title="文章列表"><i class="fa fa-bars"></i><i class="fa fa-times"></i></a>
        
            <a href="/2017/08/18/FrontFrame/Vue/VueComponents/" title="下一篇: Vue组件探秘">
                <i class="fa fa-angle-right"></i>
            </a>
        
    </div>
    <ul class="post-list"><li class="post-list-item"><a class="post-list-link" href="/2017/08/29/Tool/GitWorkflows/">Git Workflows</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/08/19/Tool/Git/">Git速查手册</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/08/18/FrontFrame/Vue/VueComponents/">Vue组件探秘</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/08/18/Induce/InduceSass/">深入Sass</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/08/18/FrontFrame/Vue/KeepAlive/">keep-alive最佳实践</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/08/18/Induce/CSS/CssLowFrequency/">CSS低频属性</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/08/02/Tool/Terminal/">Terminal配置</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/07/25/Induce/Weixin/JS-SDK/">WeChat SDK</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/07/12/Induce/Hack/Canvas/">浏览器常见Bug——Canvas</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/04/25/FrontFrame/Vue/Vuex/">Vuex</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/03/25/Induce/HTML/Video/">Mobile Video</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/03/25/FrontFrame/Vue/VueRouter/">Vue Router</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/03/21/Tool/Sublime/sublimeMac/">Sublime Mac 快捷键</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/02/14/FrontFrame/React/React/">React初探</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/01/02/Induce/CSS/CSSElementAlign/">用CSS实现元素垂直居中方案</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/12/31/Skill/norm/normCSS/">CSS前端代码规范</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/12/31/Skill/norm/normjs/">前端代码规范Javascript</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/12/31/Skill/norm/normhtml/">HTML前端代码规范</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/12/31/Skill/norm/normdev/">前端开发代码规范</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/12/27/FrontFrame/ReactNative/Components/RNCText/">React Native Text</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/12/27/FrontFrame/ReactNative/Components/RNCTextInput/">React Native TextInput</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/12/27/FrontFrame/ReactNative/Components/RNCImage/">React Native Image</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/12/27/FrontFrame/ReactNative/Components/RNComponents/">React Native 组件</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/12/26/FrontFrame/ReactNative/RNTest/">React Native 实战封装组件</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/12/26/FrontFrame/ReactNative/RNBasics/">React Native 基础</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/12/25/FrontFrame/ReactNative/RNSetOX/">React Native IOS环境搭建</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/12/25/FrontFrame/ReactNative/RNTools/">React Native开发工具</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/12/25/FrontFrame/ReactNative/RNSetAndroid/">React Native Android环境搭建（Window）</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/12/25/FrontFrame/ReactNative/RN/">React Native初探</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/05/08/Induce/Mobile/MobileGuide/">移动Web解决方案</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/04/02/Induce/JavaScript/JSInputSearch/">Input输入框的案例</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/04/02/Plug/Gulp/InduceGulp/">Gulp前端构建工具</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/04/02/Plug/Sublime/SublimeOmniMarkupPreviewer/">OmniMarkupPreviewer</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/04/02/Induce/HTML/HtmlRem/">移动H5自适应布局</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/03/02/Demo/TextShow/">BOOS信息展示与收缩</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/02/28/Demo/MobileRotate/">移动端横屏提示动画</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/02/27/Induce/Skill/OOCSS/">面向对象的CSS样式</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/02/27/Induce/Mobile/MobliePC/">关于移动端界面在PC端显示的实现</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/02/20/Induce/Node/NodeJsWeb/">Node.js实战 建立简单的Web服务器</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/02/20/Induce/CSS/animation/">CSS3动画探秘</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/01/28/Induce/Mobile/Mobile-knowledge/">移动前端知识总结</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/01/27/Induce/Ajax/Ajax/">Ajax学习计划</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/01/20/Plug/ChromePlug/">前端Chrome插件</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/01/19/Induce/JavaScript/JSTip/">原生JS TitleTip</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/01/19/Induce/Ajax/AjaxStatus/">Ajax Status请求状态</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/01/16/Interview/FrontMap/">【转】2015-2016前端知识体系</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/01/15/Induce/JavaScript/NativeJS/">原生JavaScript探索</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/01/13/Induce/HTML/HTMLbase/">HTML结构零散</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/12/27/Hexo/GitHubHexo/">使用GitHub搭建Hexo博客</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/12/27/Hexo/HexoBug/">Hexo bug</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/12/27/Hexo/HexoPlug/">Hexo插件安装</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/12/27/Hexo/Hexo/">Hexo的使用介绍</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/12/27/Hexo/HexoTheme/">Hexo 主题：SPFK</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/12/26/Skill/win7Set/">电脑优化相关</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/12/25/Induce/CSS/CssTips/">CSS小技巧收藏</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/12/25/Interview/WebFront/">web前端职业规划</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/12/25/Induce/HTML/media/">响应式布局</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/12/25/Induce/CSS/CSS/">CSS学习计划</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/12/24/Tool/Sublime/Sublimemarkdown/">Markdown使用指南</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/12/21/Tool/Sublime/Sublimebest/">Sublime Text历练</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/12/21/Induce/JavaScript/JQueryCDN/">CDN公共库</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/12/21/Plug/Sublime/SublimePackage/">Sublime插件</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/12/21/Demohttps://tuchong.com/1496450//">前端资源导航</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/12/11/Skill/BusyFront/">Busy前端工作室</a></li></ul>
    <script src="https://7.url.cn/edu/jslib/comb/require-2.1.6,jquery-1.9.1.min.js"></script>
    <script>
        $(".post-list").addClass("toc-article");
        $(".post-list-item a").attr("target","_blank");
        $("#post-nav-button > a:nth-child(2)").click(function() {
            $(".fa-bars, .fa-times").toggle();
            $(".post-list").toggle(300);
            if ($(".toc").length > 0) {
                $("#toc, #tocButton").toggle(200, function() {
                    if ($(".switch-area").is(":visible")) {
                        $("#tocButton").attr("value", valueHide);
                        }
                    })
            }
            else {
            }
        })
    </script>



    <script>
        
    </script>
</div>
      <footer id="footer">
    <div class="outer">
        <div id="footer-info">
            <div class="footer-left">
                &copy; 2017 安与生
            </div>
            <div class="footer-right">
                <a href="http://hexo.io/" target="_blank">Hexo</a>  Theme <a href="https://github.com/Jimmey-Jiang/hexo-theme-spfk" target="_blank">spfk</a> by Jimmey-Jiang
            </div>
        </div>
        
            <div class="visit">
                
                    <span id="busuanzi_container_site_pv" style='display:none'>
                        <span id="site-visit" >海贼到访数: 
                            <span id="busuanzi_value_site_uv"></span>
                        </span>
                    </span>
                
                
                    <span>, </span>
                
                
                    <span id="busuanzi_container_page_pv" style='display:none'>
                        <span id="page-visit">本页阅读量: 
                            <span id="busuanzi_value_page_pv"></span>
                        </span>
                    </span>
                
            </div>
        
    </div>
</footer>

    </div>
    <script src="https://7.url.cn/edu/jslib/comb/require-2.1.6,jquery-1.9.1.min.js"></script>
<script src="/js/main.js"></script>

    <script>
        $(document).ready(function() {
            var backgroundnum = 24;
            var backgroundimg = "url(/background/bg-x.jpg)".replace(/x/gi, Math.ceil(Math.random() * backgroundnum));
            $("#mobile-nav").css({"background-image": backgroundimg,"background-size": "cover","background-position": "center"});
            $(".left-col").css({"background-image": backgroundimg,"background-size": "cover","background-position": "center"});
        })
    </script>




	<script>
	var _hmt = _hmt || [];
	(function() {
	  var hm = document.createElement("script");
	  hm.src = "//hm.baidu.com/hm.js?819b1c6493df653afb8c7846bc4b8db6";
	  var s = document.getElementsByTagName("script")[0]; 
	  s.parentNode.insertBefore(hm, s);
	})();
	</script>


<div class="scroll" id="scroll">
    <a href="#"><i class="fa fa-arrow-up"></i></a>
    <a href="#comments"><i class="fa fa-comments-o"></i></a>
    <a href="#footer"><i class="fa fa-arrow-down"></i></a>
</div>
<script>
    $(document).ready(function() {
        if ($("#comments").length < 1) {
            $("#scroll > a:nth-child(2)").hide();
        };
    })
</script>

<script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js">
</script>

  <script language="javascript">
    $(function() {
        $("a[title]").each(function() {
            var a = $(this);
            var title = a.attr('title');
            if (title == undefined || title == "") return;
            a.data('title', title).removeAttr('title').hover(

            function() {
                var offset = a.offset();
                $("<div id=\"anchortitlecontainer\"></div>").appendTo($("body")).html(title).css({
                    top: offset.top - a.outerHeight() - 15,
                    left: offset.left + a.outerWidth()/2 + 1
                }).fadeIn(function() {
                    var pop = $(this);
                    setTimeout(function() {
                        pop.remove();
                    }, pop.text().length * 800);
                });
            }, function() {
                $("#anchortitlecontainer").remove();
            });
        });
    });
</script>


    <script type="text/javascript">
      window.onload = function(){
        document.getElementById("search").onclick = function(){
            console.log("search")
            search();
        }
      }
      function search(){
        (function(w,d,t,u,n,s,e){w['SwiftypeObject']=n;w[n]=w[n]||function(){
        (w[n].q=w[n].q||[]).push(arguments);};s=d.createElement(t);
        e=d.getElementsByTagName(t)[0];s.async=1;s.src=u;e.parentNode.insertBefore(s,e);
        })(window,document,'script','//s.swiftypecdn.com/install/v2/st.js','_st');

        _st('install','A1Pz-LKMXbrzcFg2FWi6','2.0.0');
      }
    </script>

  </div>
</body>
</html>